﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Labb3.View
{
    class Camera
    {
        int _resolutionX;
        int _resolutionY;
        public float _offsetX;
        public float _offsetY;

        public Vector2 Resolution { get { return new Vector2(_resolutionX, _resolutionY); } }

        public Camera(int resolutionX, int resolutionY)
        {
            _resolutionX = resolutionX;
            _resolutionY = resolutionY;
            _offsetX = (int)(resolutionX * 0.05);
            _offsetY = (int)(resolutionY * 0.05);
        }

        public Vector2 GetVisualCoords(Vector2 logicalVector, bool withOffset = false)
        {
            if (withOffset)
            {
                return new Vector2(logicalVector.X * (_resolutionX - _offsetX),
                logicalVector.Y * (_resolutionY - _offsetY));
            }
            return new Vector2(logicalVector.X * _resolutionX,
                logicalVector.Y * _resolutionY);
        }

        public Vector2 GetLogicalCoords(Vector2 visualVector)
        {
            float logicalX = visualVector.X / (float)_resolutionX;
            float logicalY = visualVector.Y / (float)_resolutionY;

            return new Vector2(logicalX, logicalY);
        }

        public void resize(GraphicsDeviceManager gdm)
        {            
            gdm.IsFullScreen = false;
            gdm.PreferredBackBufferWidth = _resolutionX;
            gdm.PreferredBackBufferHeight = _resolutionY;
            gdm.ApplyChanges();
        }
    }
}
